<template>
    <div class="article-lists">
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="订单类型">
                    <el-select class="w-[280px]" v-model="queryParams.type">
                        <el-option label="全部" value />
                        <el-option label="现金订单" :value="1" />
                        <el-option label="积分订单" :value="2" />
                    </el-select>
                </el-form-item>
                <el-form-item label="订单类型">
                    <el-select class="w-[280px]" v-model="queryParams.serviceType">
                        <el-option label="全部" value />
                        <el-option label="仅退款" :value="1" />
                        <el-option label="退货退款" :value="2" />
                    </el-select>
                </el-form-item>
                <el-form-item label="售后状态">
                    <el-select class="w-[280px]" v-model="queryParams.status">
                        <el-option label="全部" value />
                        <el-option
                            v-for="item in statusOptions"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </el-form-item>
                <!-- <el-form-item label="售后时间">
                    <daterange-picker
                        v-model:startTime="queryParams.startTime"
                        v-model:endTime="queryParams.endTime"
                    />
                </el-form-item> -->
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <el-table size="large" v-loading="pager.loading" :data="pager.lists">
                <el-table-column label="售后编号" prop="afterSaleSn" min-width="80" />
                <el-table-column label="订单" prop="orderSn" min-width="80" />
                <el-table-column label="售后类型" min-width="100">
                    <template #default="{ row }">
                        <span>{{ row.serviceType == 1 ? '仅退款' : '退货退款' }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="售后状态" min-width="100">
                    <template #default="{ row }">
                        <span>{{ statusMap[row.status]?.label || '_' }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="售后金额" prop="amount" min-width="100"></el-table-column>
                <el-table-column label="创建时间" min-width="80" prop="createTime">
                </el-table-column>
                <el-table-column label="操作" width="120" fixed="right">
                    <template #default="{ row }">
                        <el-button type="primary" link>
                            <router-link :to="`/afterSales/detail?id=${row.id}`">
                                查看详情
                            </router-link>
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>
<script lang="ts" setup name="articleLists">
import { usePaging } from '@/hooks/usePaging'
import { listAfterSalesPage } from '@/servers/order/api/supplyChainshouhouguanli'
const queryParams = reactive({
    type: undefined,
    serviceType: undefined,
    status: undefined
    // startTime: undefined,
    // endTime: undefined
})

const statusMap: any = {
    1: {
        label: '待审核',
        icon: ''
    },
    2: {
        label: '平台已审核',
        icon: ''
    },
    3: {
        label: '等待用户发货/退款',
        icon: ''
    },
    4: {
        label: '用户已发货',
        icon: ''
    },
    5: {
        label: '退款成功',
        icon: ''
    }
}

const statusOptions = Object.keys(statusMap).map((i) => ({
    label: statusMap[i].label,
    value: i
}))

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: listAfterSalesPage,
    params: queryParams
})

onActivated(() => {
    getLists()
})

getLists()
</script>
